package com.zhilingshenghuo.app.zhly.view.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.zhilingshenghuo.app.zhly.R;
import com.zhilingshenghuo.app.zhly.entity.EventMsgResponse;
import com.zhilingshenghuo.app.zhly.utils.ShareUtil;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.util.List;

public class MultipleItemAdapter extends BaseMultiItemQuickAdapter<EventMsgResponse, BaseViewHolder> {

    private Context context;
    private String scoreType;

    public MultipleItemAdapter(Context context, List data, String scoreType) {
        super(data);
        this.context = context;
        this.scoreType = scoreType;
        //必须绑定type和layout的关系
        addItemType(1, R.layout.item_room_record_type_send);
        addItemType(2, R.layout.item_room_record_type_rob);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, EventMsgResponse eventMsgResponse) {
        baseViewHolder.setIsRecyclable(false);
        String typeStr = "";
        if (scoreType.equals("gold")) {
            typeStr = "金币";
        } else {
            typeStr = "金豆";
        }
        if (baseViewHolder.getItemViewType() == 1) {
            TextView tvMine = baseViewHolder.getView(R.id.tvMine);
            ImageView ivIcon = baseViewHolder.getView(R.id.ivSendIcon);
            String userId = ShareUtil.getInstance().get(ShareUtil.USERID);
            if (eventMsgResponse.getUser_id() == Integer.valueOf(userId)) {
                tvMine.setVisibility(View.VISIBLE);
            }
            //头像
            if (eventMsgResponse.getFace() == null || eventMsgResponse.getFace().equals("false")) {
                Glide.with(context).load(R.drawable.icon_csc).into(ivIcon);
            } else {
                Glide.with(context).load(eventMsgResponse.getFace())
                        .apply(RequestOptions.bitmapTransform(new CircleCrop()))
                        .into(ivIcon);
            }
            //用户名
            baseViewHolder.setText(R.id.tvUserName, eventMsgResponse.getNickname());
            //时间
            baseViewHolder.setText(R.id.tvDate, eventMsgResponse.getTime());

            //标题
            baseViewHolder.setText(R.id.tvTitle, eventMsgResponse.getStake_score() + typeStr + "(" + eventMsgResponse.getNum() + "包)");

            //雷数目
            if (eventMsgResponse.getSelect().size() == 1) {
                baseViewHolder.setText(R.id.tvSendType, "一雷");
                baseViewHolder.setText(R.id.tvSelectNum, "雷号：" + eventMsgResponse.getSelect().get(0));
            } else if (eventMsgResponse.getSelect().size() == 2) {
                baseViewHolder.setText(R.id.tvSendType, "多雷");
                baseViewHolder.setText(R.id.tvSelectNum, "雷号：" + eventMsgResponse.getSelect().get(0) + "," + eventMsgResponse.getSelect().get(1));
            }
        } else if (baseViewHolder.getItemViewType() == 2) {
            if (eventMsgResponse.getClaim_score() != 0) {
                if (eventMsgResponse.getSelect().size() == 1) {
                    String userId = ShareUtil.getInstance().get(ShareUtil.USERID);
                    if (eventMsgResponse.getUser_id() == Integer.valueOf(userId)) {
                        baseViewHolder.setText(R.id.tvContent, "您参与砸蛋，获得 " + eventMsgResponse.getRob_score() + typeStr+ " 【中雷(" + eventMsgResponse.getSelect().get(0) + ")】," + "您意外损失" + eventMsgResponse.getClaim_score() + typeStr);
                    } else {
                        baseViewHolder.setText(R.id.tvContent, eventMsgResponse.getNickname() + "参与砸蛋，获得 " + eventMsgResponse.getRob_score() + typeStr+ " 【中雷(" + eventMsgResponse.getSelect().get(0) + ")】," + "意外损失" + eventMsgResponse.getClaim_score() + typeStr);
                    }
                } else if (eventMsgResponse.getSelect().size() == 2) {
                    String userId = ShareUtil.getInstance().get(ShareUtil.USERID);
                    if (eventMsgResponse.getUser_id() == Integer.valueOf(userId)) {
                        baseViewHolder.setText(R.id.tvContent, "您参与砸蛋，获得 " + eventMsgResponse.getRob_score() + typeStr+ " 【中雷(" + eventMsgResponse.getSelect().get(0) + "," + eventMsgResponse.getSelect().get(1) + ")】," + "您意外损失" + eventMsgResponse.getClaim_score() + typeStr);
                    } else {
                        baseViewHolder.setText(R.id.tvContent, eventMsgResponse.getNickname() + "参与砸蛋，获得 " + eventMsgResponse.getRob_score() + typeStr+" 【中雷(" + eventMsgResponse.getSelect().get(0) + "," + eventMsgResponse.getSelect().get(1) + ")】," + "意外损失" + eventMsgResponse.getClaim_score() + typeStr);
                    }
                }
            } else {
                if (eventMsgResponse.getSelect().size() == 1) {
                    String userId = ShareUtil.getInstance().get(ShareUtil.USERID);
                    if (eventMsgResponse.getUser_id() == Integer.valueOf(userId)) {
                        baseViewHolder.setText(R.id.tvContent, "您参与砸蛋，获得 " + eventMsgResponse.getRob_score()  + typeStr+ " 【未中雷(" + eventMsgResponse.getSelect().get(0) + ")】,");
                    } else {
                        baseViewHolder.setText(R.id.tvContent, eventMsgResponse.getNickname() + "参与砸蛋，获得 " + eventMsgResponse.getRob_score()  + typeStr+ "  【未中雷(" + eventMsgResponse.getSelect().get(0) + ")】");
                    }
                } else if (eventMsgResponse.getSelect().size() == 2) {
                    String userId = ShareUtil.getInstance().get(ShareUtil.USERID);
                    if (eventMsgResponse.getUser_id() == Integer.valueOf(userId)) {
                        baseViewHolder.setText(R.id.tvContent, "您参与砸蛋，获得 " + eventMsgResponse.getRob_score() + typeStr+ " 【未中雷(" + eventMsgResponse.getSelect().get(0) + "," + eventMsgResponse.getSelect().get(1) + ")】");
                    } else {
                        baseViewHolder.setText(R.id.tvContent, eventMsgResponse.getNickname() + "参与砸蛋，获得 " + eventMsgResponse.getRob_score()  + typeStr+ " 【未中雷(" + eventMsgResponse.getSelect().get(0) + "," + eventMsgResponse.getSelect().get(1) + ")】");
                    }
                }
            }
        }
    }
}
